package com.guli.mall.pms.controller;

import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

import com.guli.mall.pms.entity.SpuInfoDescEntity;
import com.guli.mall.pms.service.SpuInfoDescService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * spu信息介绍
 *
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-09-17 11:37:22
 */
@RestController
@RequestMapping("pms/spuinfodesc")
public class SpuInfoDescController {
    @Autowired
    private SpuInfoDescService spuInfoDescService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取spuInfoDesc分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size) {
        PageUtils page = spuInfoDescService.queryPage(currentPage,size);

        return R.ok().put("page", page);
    }



    @GetMapping("/info/{spuId}")
    @ApiOperation("根据spuId获取SpuInfoDesc")
    public R info(@PathVariable("spuId") Long spuId) {
            SpuInfoDescEntity spuInfoDesc = spuInfoDescService.getById(spuId);

        return R.ok().put("spuInfoDesc", spuInfoDesc);
    }

    @PostMapping("/save")
    @ApiOperation("插入SpuInfoDesc")
    public R save(@RequestBody SpuInfoDescEntity spuInfoDesc) {
            spuInfoDescService.save(spuInfoDesc);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据spuId更新SpuInfoDesc")
    public R update(@RequestBody SpuInfoDescEntity spuInfoDesc) {
            spuInfoDescService.updateById(spuInfoDesc);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据spuId批量删除SpuInfoDesc")
    public R delete(@RequestBody Long[] spuIds) {
            spuInfoDescService.removeByIds(Arrays.asList(spuIds));

        return R.ok();
    }

}
